package org.adorsys.aderp.jpa.api.xchange;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.adorsys.aderp.jpa.api.audit.AbstractAuditRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

public abstract class AbstractXchangeAuditRecordService<T extends AbstractAuditRecord> implements XchangeAuditRecordService{
	
	public abstract Page<T> findByModifOnGreaterThan(Date modifOn, Pageable pageable);

	@Override
	public MapPage loadAuditRecord(Date modifOn, Pageable pageable){
		Page<T> found = findByModifOnGreaterThan(modifOn, pageable);
		List<Map<String, String>> content = new ArrayList<Map<String,String>>(found.getSize());
		for (T t : found) {
			content.add(t.toDataMap());
		}
		return new MapPage(content , new PageRequest(found.getNumber(), found.getSize()), found.getTotalElements());
	}
}
